package com.xncoding.tomcat.socket01;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyTomcat {
    /**
     * 设定启动和监听端口
     */
    private int port = 8090;

    /**
     * 启动函数
     *
     * @throws IOException
     */
    public void start() throws IOException {
        System.out.println("my tomcat starting...");
        String responseData = "6666666";
        ServerSocket socket = new ServerSocket(port);
        while (true) {
            Socket accept = socket.accept();
            OutputStream outputStream = accept.getOutputStream();
            String responseText = HttpProtocolUtil.getHttpHeader200(responseData.length()) + responseData;
            outputStream.write(responseText.getBytes());
            accept.close();
        }
    }

    /**
     * 启动入口
     */
    public static void main(String[] args) throws IOException {
        MyTomcat tomcat = new MyTomcat();
        tomcat.start();
    }
}
